#include "../header.h"


//信号被注册的函数
void sigfun(int signo)
{
    if(signo == SIGINT)   //! ctrl + c
        printf("SIGINT 此信号已经被编程!\n");
    //! ctrl + '\'
    if(signo == SIGQUIT)  
        printf("SIGQUIT 此信号已经被编程!\n");
     if(signo == SIGTSTP) //! ctrl + z 
        printf("SIGTSTP 此信号已经被编程!\n");
}

int main(int argc, char const *argv[])
{
    struct sigaction newact = {0},oldact = {0};
    newact.sa_handler = sigfun;
    newact.sa_flags = 0 ;
    //清空掩码值
    sigemptyset(&newact.sa_mask);
    sigaction(SIGINT,&newact,&oldact);
    sigaction(SIGQUIT,&newact,&oldact);
    sigaction(SIGTSTP,&newact,&oldact);
    
    int num = 10;
    while (num--)
    {
        printf("this is signal test:%d\n",getpid());
        sleep(1);
    }
    
    //10秒钟以后，可以恢复。
    sigaction(SIGINT,&oldact,NULL);
    sigaction(SIGQUIT,&oldact,NULL);
    sigaction(SIGTSTP,&oldact,NULL);
    pause();

    return 0;
}
